package com.roy.minimq.remoting.domain.netty;

import com.roy.minimq.remoting.domain.entity.RemotingCommand;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.Charset;
import java.util.List;

/**
 * @author ：楼兰
 * @date ：Created in 2021/8/9
 * @description:
 **/
public class NettyDecoder extends ByteToMessageDecoder {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> out) throws Exception {
        logger.info("NettyDecoder decode: byteBuf "+byteBuf.toString(Charset.forName("utf-8")));
        RemotingCommand command = RemotingCommand.decodeFrom(byteBuf);
        out.add(command);
    }
}
